package com.aaa.javaweb.dao.impl;

import com.aaa.javaweb.dao.RoleDao;
import com.aaa.javaweb.entity.Role;
import com.aaa.javaweb.until.JDBCUntil;

import java.util.List;
import java.util.Map;

public class RoleDaoImpl implements RoleDao {
    @Override
    public List<Map> queryAll() {
        String sql="select * from t_juese";
        List<Map> maps = JDBCUntil.selectMap(sql);
        return maps;
    }

    @Override
    public int delGust(String gid) {
        String sql="delete from t_juese where id=?";
        return JDBCUntil.Updateout(sql,gid);
    }

    @Override
    public int add(Role g) {
        if(g.getId()==null){
            String sql="insert into t_juese values(?,?)";
            return JDBCUntil.Updateout(sql,g.getId(),g.getJname());
        }else{
            String sql="update t_juese set jname=? where id=?";
            return JDBCUntil.Updateout(sql,g.getJname(),g.getId());
        }
    }

    @Override
    public Map findGustById(String gid) {
        String sql="select * from t_juese where id=?";
        List<Map> maps = JDBCUntil.selectMap(sql, gid);//
        //
        Map m=maps.get(0);
        return m;
    }

    @Override
    public List<Map> queryid(String rid) {
        String sql="select * from t_juese tj JOIN t_rolemenu trm ON tj.id=trm.jsid JOIN t_menu tm ON tm.id=trm.cdid where tj.id=?";
        return JDBCUntil.selectMap(sql,rid);
    }

    @Override
    public int del(String rid) {
        String sql="delete from t_rolemenu where jsid=?";
        return JDBCUntil.Updateout(sql,rid);
    }

    @Override
    public int addid(String s, String rid) {
        String sql="insert into t_rolemenu (jsid,cdid) values(?,?)";
        return JDBCUntil.Updateout(sql,rid,s);
    }
}
